| 1 |
import { |
| 2 |
getNextDocumentBySlug, |
| 3 |
getDocumentBySlug, |
| 4 |
getPreviousDocumentBySlug, |
| 5 |
documentFilePaths, |
| 6 |
} from '../../utils/mdx-utils' |
| 7 |
|
| 8 |
import Layout from '../../components/Layout' |
| 9 |
import SEO from '../../components/SEO' |
| 10 |
import type { GetStaticProps } from 'next' |
| 11 |
|
| 12 |
interface FrontMatter { |
| 13 |
title: string |
| 14 |
description: string |
| 15 |
} |
| 16 |
|
| 17 |
interface DocumentPageProps { |
| 18 |
source: string |
| 19 |
frontMatter: FrontMatter |
| 20 |
} |
| 21 |
|
| 22 |
export default function DocumentPage({ |
| 23 |
source, |
| 24 |
frontMatter, |
| 25 |
}: DocumentPageProps) { |
| 26 |
return ( |
| 27 |
<Layout> |
| 28 |
<SEO |
| 29 |
title={frontMatter.title} |
| 30 |
description={frontMatter.description} |
| 31 |
/> |
| 32 |
<article className="p-2 pt-4 lg:p-4 w-full"> |
| 33 |
<header> |
| 34 |
<h1 className="text-3xl md:text-5xl dark:text-white mb-12"> |
| 35 |
{frontMatter.title} |
| 36 |
</h1> |
| 37 |
{frontMatter.description && ( |
| 38 |
<p className="text-xl mb-4">{frontMatter.description}</p> |
| 39 |
)} |
| 40 |
</header> |
| 41 |
<main> |
| 42 |
<article |
| 43 |
className="prose dark:prose-invert" |
| 44 |
dangerouslySetInnerHTML={{ __html: source }} |
| 45 |
/> |
| 46 |
</main> |
| 47 |
</article> |
| 48 |
</Layout> |
| 49 |
) |
| 50 |
} |
| 51 |
|
| 52 |
export const getStaticProps: GetStaticProps = async ({ params }) => { |
| 53 |
if (params) { |
| 54 |
const { source, data } = await getDocumentBySlug(params.slug as string) |
| 55 |
const prevDocument = getPreviousDocumentBySlug(params.slug as string) |
| 56 |
const nextDocument = getNextDocumentBySlug(params.slug as string) |
| 57 |
|
| 58 |
return { |
| 59 |
props: { |
| 60 |
source, |
| 61 |
frontMatter: data, |
| 62 |
prevDocument, |
| 63 |
nextDocument, |
| 64 |
}, |
| 65 |
} |
| 66 |
} |
| 67 |
return { props: {} } |
| 68 |
} |
| 69 |
|
| 70 |
export const getStaticPaths = async () => { |
| 71 |
const paths = documentFilePaths |
| 72 |
// Remove file extensions for page paths |
| 73 |
.map((path) => path.replace(/\.mdx?$/, '')) |
| 74 |
// Map the path into the static paths object required by Next.js |
| 75 |
.map((slug) => ({ params: { slug } })) |
| 76 |
|
| 77 |
return { |
| 78 |
paths, |
| 79 |
fallback: false, |
| 80 |
} |
| 81 |
} |